app.get("/get1",(req,res)=>{
        res.send = function (data) {
             res.setHeader("Access-Control-Allow-Origin", "*");
            // res.setHeader("Access-Control-Allow-Headers", "X-Requested-With");
             res.setHeader("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
            res.setHeader("Content-Type", "application/json;charset=utf-8");
            res.end(data);
            res.alreadySend = true;
        }
        let r={
            "data":"get1 ok"
        }
        if(req.params.callback2){
            res.send(`${req.params.callback2}(${JSON.stringify(r)})`)
            return;
        }
      res.send(JSON.stringify(r))

})




app.post("/postJson",(req,res)=>{
        res.send = function (data) {
             res.setHeader("Access-Control-Allow-Origin", "http://web.com");
             res.setHeader("Access-Control-Allow-Headers", "content-type");
             res.setHeader("Access-Control-Allow-Methods", "POST,GET,DELETE,OPTIONS");
             res.setHeader("Access-Control-Max-Age", "10");
             res.setHeader("X-Powered-By", ' 3.2.1')
             res.setHeader("Content-Type", "application/json;charset=utf-8");
             res.setHeader("Access-Control-Allow-Credentials", "true");
            res.end(data);
            res.alreadySend = true;
        }
        let r={
            "data":"postjson ok"
        }
        res.send(JSON.stringify(r))

})


app.mapping("/postJson",(req,res)=>{
     console.log("-----------"+req.method)
        res.send = function (data) {
             res.setHeader("Access-Control-Allow-Origin", "http://web.com");
            // res.setHeader("Access-Control-Allow-Headers", "content-type");
             res.setHeader("Access-Control-Allow-Headers","*");
          
             res.setHeader("Access-Control-Allow-Methods", "POST,GET,DELETE,OPTIONS");
             res.setHeader("Access-Control-Max-Age", "10");
             res.setHeader("X-Powered-By", ' 3.2.1')
             res.setHeader("Content-Type", "application/json;charset=utf-8");
             res.setHeader("Access-Control-Allow-Credentials", "true");
             res.end(data);
             res.alreadySend = true;
        }
        let r={
            "data":"postjson options"
        }
        res.send(JSON.stringify(r))
})


app.get("/getCookie",(req,res)=>{
     res.send = function (data) {
             res.setHeader("Access-Control-Allow-Origin", "http://web.com");
             res.setHeader("Access-Control-Allow-Headers", "*");
             res.setHeader("Access-Control-Allow-Methods", "POST,GET,DELETE,OPTIONS");
             res.setHeader("Access-Control-Allow-Credentials", "true");
               res.setHeader("Access-Control-Max-Age", "10");
             res.setHeader("X-Powered-By", ' 3.2.1')
             res.setHeader("Content-Type", "application/json;charset=utf-8");
             res.end(data);
             res.alreadySend = true;
        }
    res.send(M.result(req.cookies));
})



app.get("/setCookie",(req,res)=>{
     res.send = function (data) {
             res.setHeader("Access-Control-Allow-Origin", "http://web.com");
             res.setHeader("Access-Control-Allow-Headers", "*");
             res.setHeader("Access-Control-Allow-Methods", "POST,GET,DELETE,OPTIONS");
             res.setHeader("Access-Control-Allow-Credentials", "true");
               res.setHeader("Access-Control-Max-Age", "10");
             res.setHeader("X-Powered-By", ' 3.2.1')
             res.setHeader("Content-Type", "application/json;charset=utf-8");
             res.end(data);
             res.alreadySend = true;
        }
         // res.setHeader("Set-Cookie", querystring.stringify({"aa":77}, " ;"));
         //无法为其他域设置cookie
        //res.setHeader("Set-Cookie", "minglie=77; Domain=web.com");
       res.send(M.result(req.cookies));
})




app.get("/getHeader",(req,res)=>{
     res.send = function (data) {
             res.setHeader("Access-Control-Allow-Origin", "http://web.com");
           
             //res.setHeader("Access-Control-Allow-Headers", "*");
             res.setHeader("Access-Control-Allow-Headers", "Content-Type,x-header1");

             res.setHeader("Access-Control-Allow-Methods", "POST,GET,DELETE,OPTIONS");
            // res.setHeader("Access-Control-Allow-Credentials", "true");
               res.setHeader("Access-Control-Max-Age", "10");
             res.setHeader("X-Powered-By", ' 3.2.1')
             res.setHeader("Content-Type", "application/json;charset=utf-8");
             res.end(data);
             res.alreadySend = true;
        }

        let hs= req.headers['x-header1']

       res.send(M.result(hs));
})




app.begin((req,res)=>{
    if(req.url.startsWith("/_run_")){
        return;
    }
    console.log(req.method+" "+req.url,req.body)
})